{
  LX Scripts module

  Based on modo's SDK lxscripts.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012, David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_Scripts;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result;

const
  LXa_SCRIPTSYSSERVICE      = 'scriptsysservice'     ;
  LXa_SCRIPTMANAGER         = 'scriptservice'        ;
  LXa_TEXTSCRIPTINTERPRETER = 'textscriptinterpreter';
  LXa_SCRIPT                = 'script'               ;
  LXa_PLATFORMSERVICE       = 'platformservice'      ;
  LXa_SCRIPTLINEEVENT       = 'scriptlineevent'      ;

  LXfSCRIPTSRV_CREATE       = $0001;
  LXfSCRIPTSRV_REMOVE       = $0002;
  LXfSCRIPTSRV_LINE_ACTION  = $0003;

  LXiOSTYPE_WIN32           = 1;
  LXiOSTYPE_MACOSX          = 2;
  LXiOSTYPE_LINUX           = 3;

  LXsLOG_SCRIPTSYS          = 'scripts';

  LXu_SCRIPTSYSSERVICE      = '{5046C663-7990-44d5-84CB-A859101B1C59}';
  LXu_SCRIPTMANAGER         = '{3699E7C5-44B8-4e07-B8CA-E26899CD7B3B}';
  LXu_TEXTSCRIPTINTERPRETER = '{D612FFCE-4B94-4823-A0A7-CC7CA2DDC3D6}';
  LXu_SCRIPT                = '{33C03F3F-A692-4bf4-8AB4-C5A95CA7930C}';
  LXu_PLATFORMSERVICE       = '{B9596D64-8CB3-4943-8415-7EDF527AE513}';
  LXu_SCRIPTLINEEVENT       = '{DABF6619-A4B5-4919-8389-8C54B39422E4}';

type
  ILxScriptSysService = interface
  [LXu_SCRIPTSYSSERVICE]
    function ScriptQuery (  out VObj              ) : LxResult;
    function Count       (      Count   : PUInt32 ) : LxResult;
    function ByIndex     (      Index   : UInt32  ;
                            out VObj              ) : LxResult;
    function NameByIndex (      Index   : UInt32  ;
                          const Name    : PPChar  ) : LxResult;
    function Lookup      (const Name    : PChar   ;
                            out VObj              ) : LxResult;
    function UserName    (      Manager : IUnknown;
                          const Name    : PPChar  ) : LxResult;
    function Desc        (      Manager : IUnknown;
                          const Name    : PPChar  ) : LxResult;
    function ResolveAlias(const Alias   : PChar   ;
                          const Path    : PPChar  ) : LxResult;
  end;

  ILxScriptManager = interface
  [LXu_SCRIPTMANAGER]
    function Name     (const Name          : PPChar  ) : LxResult;
    function Flags    (      Flags         : PInteger) : LxResult;
    function Count    (      Count         : PUInt32 ) : LxResult;
    function ByIndex  (      Index         : UInt32  ;
                         out VObj                    ;
                             Write         : Integer ) : LxResult;
    function Lookup   (const Hash          : PChar   ;
                         out VObj                    ;
                             Write         : Integer ;
                             TryAsUserName : Integer ) : LxResult;
    function ReadWrite(const Hash          : PChar   ;
                             Index         : Integer ) : LxResult;
    function New      (const Name_         : PChar   ;
                         out VObj                    ) : LxResult;
    function Remove   (      Script        : IUnknown) : LxResult;
    function Validate (      Script        : IUnknown;
                             Msg           : IUnknown) : LxResult;
    function Run      (      Script        : IUnknown;
                             ExecFlags     : Integer ;
                       const Args          : PChar   ;
                             Msg           : IUnknown) : LxResult;
  end;

  ILxTextScriptInterpreter = interface
  [LXu_TEXTSCRIPTINTERPRETER]
    function ValidateFileType(      Script    : IUnknown;
                              const FirstLine : PChar   ) : LxResult;
    function Validate        (      Script    : IUnknown;
                                    Msg       : IUnknown) : LxResult;
    function Run             (      Script    : IUnknown;
                                    ExecFlags : Integer ;
                              const Args      : PChar   ;
                                    Msg       : IUnknown) : LxResult;
  end;

  ILxScript = interface
  [LXu_SCRIPT]
    function Hash       (const Hash         : PPChar ) : LxResult;
    function UserName   (const UserName     : PPChar ) : LxResult;
    function SetUserName(const UserName_    : PChar  ) : LxResult;
    function Desc       (const Desc         : PPChar ) : LxResult;
    function SetDesc    (const Desc_        : PChar  ) : LxResult;
    function Icon       (const Icon         : PPChar ) : LxResult;
    function HelpKey    (const Args         : PChar  ;
                         const Key          : PPChar ) : LxResult;
    function Manager    (  out VObj                  ) : LxResult;
    function GetBuffer  (const Buffer       : PPChar ;
                               BufferLength : PUInt32) : LxResult;
    function SetBuffer  (const Buffer       : PChar  ;
                               BufferLength : UInt32 ) : LxResult;
  end;

  ILxPlatformService = interface
  [LXu_PLATFORMSERVICE]
    function ScriptQuery      (  out VObj               ) : LxResult;
    function LicensedTo       (const Licensee : PPChar  ) : LxResult;
    function ExpiresIn        (      DaysLeft : PInteger) : LxResult;
    function SerialNumber     (const Serial   : PPChar  ) : LxResult;
    function NumLicenses      (      Licenses : PInteger) : LxResult;
    function AppName          (const Name     : PPChar  ) : LxResult;
    function AppVersion       (      Version  : PInteger) : LxResult;
    function AppBuild         (      Build    : PInteger) : LxResult;
    function IsHeadless                                   : LxResult;
    function OSType           (      &Type    : PInteger) : LxResult;
    function OSName           (const Name     : PPChar  ) : LxResult;
    function OSVersion        (const Version  : PPChar  ) : LxResult;
    function PathCount        (      Count    : PInteger) : LxResult;
    function PathByIndex      (      Index    : Integer ;
                               const Path     : PPChar  ) : LxResult;
    function PathNameByIndex  (      Index    : Integer ;
                               const Name     : PPChar  ) : LxResult;
    function ImportPathCount  (      Index    : PInteger) : LxResult;
    function ImportPathByIndex(      Index    : Integer ;
                               const Path     : PPChar  ) : LxResult;
    function IsApp64Bit                                   : LxResult;
  end;

  ILxScriptLineEvent = interface
  [LXu_SCRIPTLINEEVENT]
    function Index (    Index : PUInt32) : LxResult;
    function Script(out VObj           ) : LxResult;
  end;

function LXe_SCRIPT_UNKNOWN            : LxResult;
function LXe_SCRIPT_ERROR              : LxResult;
function LXe_SCRIPT_OPAQUE             : LxResult;
function LXe_SCRIPT_READONLY           : LxResult;
function LXe_SCRIPT_ALREADY_EXISTS     : LxResult;
function LXe_SCRIPT_NOT_ENOUGH_ARGS    : LxResult;
function LXe_SCRIPT_TOO_MANY_ARGS      : LxResult;
function LXe_SCRIPT_RECOGNIZED_INVALID : LxResult;
function LXe_SCRIPT_WARNING            : LxResult;  // OK, not FAIL

implementation

function LXe_SCRIPT_UNKNOWN            : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_SCRIPT, 1);
end;
function LXe_SCRIPT_ERROR              : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_SCRIPT, 2);
end;
function LXe_SCRIPT_OPAQUE             : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_SCRIPT, 3);
end;
function LXe_SCRIPT_READONLY           : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_SCRIPT, 4);
end;
function LXe_SCRIPT_ALREADY_EXISTS     : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_SCRIPT, 5);
end;
function LXe_SCRIPT_NOT_ENOUGH_ARGS    : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_SCRIPT, 6);
end;
function LXe_SCRIPT_TOO_MANY_ARGS      : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_SCRIPT, 7);
end;
function LXe_SCRIPT_RECOGNIZED_INVALID : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_SCRIPT, 8);
end;
function LXe_SCRIPT_WARNING            : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_SCRIPT, 8);
end;

end.

